package com.interest.modules.movie.service.impl;

import com.interest.modules.movie.dao.MovieMapper;
import com.interest.modules.movie.entity.Movie;
import com.interest.modules.movie.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

/**
 * Created by yangfeng on 16-12-5.
 */
@Service("movieService")
public class MovieServiceImpl implements MovieService {
    @Autowired
    private MovieMapper movieMapper;

    @Override
    public List<Movie> getMovie() {
        return movieMapper.selectList();
    }

    @Override
    public Movie getRandom() {
        List<Movie> movies = getMovie();
        int index = new Random().nextInt(movies.size());
        return movies.get(index);
    }
}
